package zero.tech.games.logic.event;

import org.apache.commons.lang3.StringUtils;

import zero.tech.core.event.EventListener;
import zero.tech.core.event.EventType;
import zero.tech.core.work.WorkManager;
import zero.tech.games.logic.common.CacheRoom;
import zero.tech.games.logic.common.Room;
import zero.tech.games.logic.work.OfflineFromRoom;
import zero.tech.wsnet.controller.LogicController;
import zero.tech.wsnet.data.NetEventType;

public class PlayerOffline implements EventListener{

	@Override
	public EventType netEventType() {
		return NetEventType.ENGINE_PLAYER_OFFLINE;
	}

	@Override
	public void notifyEvent(Object... objs) {
		LogicController logicController= (LogicController) objs[0];
		String roomId=logicController.getRoomId();
		if(StringUtils.isNotBlank(roomId)) {
			Room room = CacheRoom.getCache().getRooms().get(roomId);
			if (room != null) {
				WorkManager.getManager().submit(OfflineFromRoom.class,room,logicController);
			}
		}	
	}

	@Override
	public boolean asynchronous() {
		return false;
	}

}
